int x,y;
int myWidth,myHeight,rectWidth,rectHeight;
Rectangulo rec1,rec2;


void setup(){
  colorMode(HSB);
  myWidth=400;
  myHeight=400;
  rectWidth=100;
  rectHeight=80;
  size(myWidth,myHeight);
  x=width/2;
  y=height/2;
  rec1=new Rectangulo(x-50,y-60,rectWidth,rectHeight,color(#F05900));
  rec2=new Rectangulo(x,y,rectWidth,rectHeight,color(#00FF00));
}

void draw(){
  background(255);
  rec1.draw();
  rec2.draw();
  stroke(0);
  fill(0,0,0);
  box(15,30, 20);
}

void mouseMoved(){
boolean resultado = rec1.revisarPosicion(mouseX,mouseY);
if(resultado)
rec1.cambiarBrillo();
else
rec1.reiniciarColor();
}

class Rectangulo
{
  int posX,posY;
  int rectWidth,rectHeight;
  color rectColor;  
  color origColor;
  boolean mouseIn;
  
  Rectangulo (int x1, int y1, int width1, int height1, color color1){
  posX=x1;
  posY=y1;
  rectWidth=width1;
  rectHeight=height1;
  rectColor=color1;
  origColor=color1;
  }
  
  void draw(){
  fill(rectColor); 
  rect(posX,posY,rectWidth,rectHeight);
  }
  
  void cambiarBrillo()
  {  
  rectColor = color(  hue(rectColor),
                      saturation(rectColor),
                      brightness(rectColor)+80
                      ); 
  }
  
  void reiniciarColor()
  {
  rectColor = origColor;
  }
  
  boolean revisarPosicion(int mX,int mY){
  if(mX>posX && mX< (posY+rectWidth))
  {
    if(mY>posX && mY<(posY+rectHeight))
    mouseIn = true;
    else
    mouseIn = false;    
  }  
  else
  mouseIn = false;
return mouseIn;
}
}



